package com.ruoyi.map.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruoyi.map.domain.PmsLabel;
import com.ruoyi.map.mapper.PmsLabelMapper;
import com.ruoyi.map.query.PmsLabelQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;



/**
 * 商品标签Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class PmsLabelService {
    @Autowired
    private PmsLabelMapper pmsLabelMapper;

    /**
     * 查询商品标签
     *
     * @param id 商品标签主键
     * @return 商品标签
     */
    public PmsLabel selectById(Integer id) {
        return pmsLabelMapper.selectById(id);
    }

    /**
     * 查询商品标签列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 商品标签
     */
    public List<PmsLabel> selectList(PmsLabelQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<PmsLabel> qw = new QueryWrapper<>();
        String labelNameLike = query.getLabelName();
        if (!StringUtils.isEmpty(labelNameLike)) {
            qw.like("label_name", labelNameLike);
        }
        Integer status = query.getStatus();
        if (status != null) {
            qw.eq("status", status);
        }
        return pmsLabelMapper.selectList(qw);
    }

    /**
     * 新增商品标签
     *
     * @param pmsLabel 商品标签
     * @return 结果
     */
    public int insert(PmsLabel pmsLabel) {
        pmsLabel.setCreateTime(LocalDateTime.now());
        return pmsLabelMapper.insert(pmsLabel);
    }

    /**
     * 修改商品标签
     *
     * @param pmsLabel 商品标签
     * @return 结果
     */
    public int update(PmsLabel pmsLabel) {
        return pmsLabelMapper.updateById(pmsLabel);
    }


    public List<PmsLabel> getLabelList(Long[] labelIds) {
        return pmsLabelMapper.getLabelList(labelIds);
    }

    /**
     * 批量删除商品标签
     *
     * @param ids 需要删除的商品标签主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return pmsLabelMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除商品标签信息
     *
     * @param id 商品标签主键
     * @return 结果
     */
    public int deleteById(Long id) {
        return pmsLabelMapper.deleteById(id);
    }

    public List<PmsLabel> labelList() {
        return pmsLabelMapper.labelList();
    }
}
